package com.bosi.exmple.chat.handler;

import com.bosi.exmple.chat.entity.User;
import com.bosi.exmple.chat.entity.WSRequest;
import com.bosi.exmple.message.Message;
import com.bosi.exmple.message.MessageService;

import java.util.function.Function;

/**
 * 推送消息处理
 */
public class TestHandler implements Function<WSRequest,Object> {
    private final MessageService messageService;

    public TestHandler(MessageService messageService) {
        this.messageService = messageService;
    }


    @Override
    public Object apply(WSRequest req) {
        Message message = req.getMessage();
        User user = (User) req.getSession().get("user");
        message.getHeader().put("game",user.getGame());
        messageService.publish(message);
        return null;
    }
}
